home *** CD-ROM | disk | FTP | other *** search
/ SGI Performance Co-Pilot 1.3 / SGI Performance Co-Pilot 1.3.iso / dist / dist6.4 / pcp.idb / usr / pcp / lib / pmgadgets-args.z / pmgadgets-args
Text File  |  1997-04-03  |  5KB  |  231 lines

  1. #  Copyright (c) 1994 Silicon Graphics, Inc.
  2. #  ALL RIGHTS RESERVED.
  3. #  U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND
  4. #  Use, duplication or disclosure by the Government is subject to
  5. #  restrictions as set forth in FAR 52.227.19(c)(2) or subparagraph
  6. #  (c)(1)(ii) of the Rights in Technical Data and Computer Software clause
  7. #  at DFARS 252.227-7013 and/or similar or successor clauses in the FAR,
  8. #  or the DOD or NASA FAR Supplement.  Contractor/manufacturer is Silicon
  9. #  Graphics, Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  10. #  THIS SOFTWARE CONTAINS CONFIDENTIAL AND PROPRIETARY INFORMATION OF
  11. #  SILICON GRAPHICS, INC.  ANY DUPLICATION, MODIFICATION, DISTRIBUTION, OR
  12. #  DISCLOSURE IS STRICTLY PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN
  13. #  PERMISSION OF SILICON GRAPHICS, INC.
  14. # /
  15.  
  16. #
  17. # $Id: pmgadgets-args,v 2.3 1997/03/26 02:52:57 kenmcd Exp $
  18. #
  19.  
  20. prog=`basename $0`
  21.  
  22. #
  23. # Standard usage and command-line argument parsing for pmgadgets front ends.
  24. # This file should be included by pmgadgets front end scripts to present a
  25. # consistent interface. See pmgadgets(1) for more information.
  26. #
  27.  
  28. #
  29. # The front end scripts should call _pmgadgets_usage after their own usage 
  30. # information in a subroutine called _usage. The _usage subroutine may be 
  31. # called by either _pmgadgets_usage or _pmgadgets_args.
  32. #
  33.  
  34. _pmgadgets_usage()
  35. {
  36.     echo '
  37.   -h           host        metrics source is PMCD on host
  38.   -n           namespace   use an alternative PMNS
  39.   -t           interval    change the default update interval
  40.   -delta       interval    change the default update interval
  41.   -z                       set reporting timezone to local time for host
  42.                            from -h
  43.   -Z           timezone    set reporting timezone
  44.   -zoom        factor      make the gadgets bigger by a factor of 1, 2, 3 or 4
  45.   -infofont    fontname    use fontname for info dialogs text
  46.   -defaultfont fontname    use fontname by default for label gadgets
  47.  
  48.   -display     display-string
  49.   -title       title-string
  50.   -geometry    geometry-string
  51.   -name        name-string
  52.   -xrm         resource [-xrm ..]'
  53. }
  54.  
  55. #
  56. # One of the first actions of a front end script should be to call 
  57. # _pmgadgets_args. It sets the following variables:
  58. #
  59. # host        the host specified with -h.
  60. # interval    the update interval specified by the user, 0 indicates it
  61. #        was not specified. The caller must pass this on to pmgadgets,
  62. #               unlike $host which is included in $args.
  63. # args          The list of args that pmgadgets will comprehend and use.
  64. # otherArgs     The arguments pmgadgets will not understand and should be
  65. #               handled by the front end script.
  66. # titleArg    The title the user prefers. If empty, the title should be
  67. #               provided by the front end script.
  68. # prog        The name of the program.
  69. # namespace    The namespace (including the flag) if specified, else empty
  70. #               eg "-n foo"
  71. #
  72.  
  73. _pmgadgets_args()
  74. {
  75.  
  76. host=""
  77. args=""
  78. otherArgs=""
  79. titleArg=""
  80. namespace=""
  81. interval=0
  82.  
  83. while [ $# -gt 0 ]
  84. do
  85.     case $1
  86.     in
  87.     -g*|-d*|-fg|-bg|-name|-xrm)
  88.         # assume an X11 argument
  89.         if [ $# -lt 2 ]
  90.         then
  91.         echo "$prog: $1 requires one argument"
  92.         _usage
  93.         exit 1
  94.         fi
  95.         args="$args $1 '$2'"
  96.         shift
  97.         ;;
  98.  
  99.     -title)
  100.         # assume an X11 argument
  101.         if [ $# -lt 2 ]
  102.         then
  103.         echo "$prog: $1 requires one argument"
  104.         _usage
  105.         exit 1
  106.         fi
  107.         titleArg="$2"
  108.         shift
  109.         ;;
  110.  
  111.     -D|-Z|-delta|-zoom|-infofont|-defaultfont)
  112.         if [ $# -lt 2 ]
  113.         then
  114.         echo "$prog: $1 requires one argument"
  115.         _usage
  116.         exit 1
  117.         fi
  118.         args="$args $1 '$2'"
  119.         shift
  120.         ;;
  121.  
  122.     -D*|-Z*|-z)
  123.         args="$args $1"
  124.         ;;
  125.  
  126.     -h)
  127.         if [ $# -lt 2 ]
  128.         then
  129.         echo "$prog: $1 requires one argument"
  130.         _usage
  131.         exit 1
  132.         fi
  133.         host=$2
  134.         args="$args -h $2"
  135.         shift
  136.         ;;
  137.  
  138.     -t)
  139.         if [ $# -lt 2 ]
  140.         then
  141.         echo "$prog: $1 requires one argument"
  142.         _usage
  143.         exit 1
  144.         fi
  145.         interval=$2
  146.         shift
  147.         ;;
  148.  
  149.     -n)
  150.         if [ $# -lt 2 ]
  151.         then
  152.         echo "$prog: $1 requires one argument"
  153.         _usage
  154.         exit 1
  155.         fi
  156.         namespace="-n $2"
  157.         args="$args -n $2"
  158.         shift
  159.         ;;
  160.  
  161.     *)
  162.         otherArgs="$otherArgs $1"
  163.         ;;
  164.  
  165.     esac
  166.     shift
  167. done
  168. }
  169.  
  170. # standard fatal error reporting
  171. # Usage: _pmgadgets_error message goes in here
  172. #        _pmgadgets_error -f file
  173. #
  174. _pmgadgets_error()
  175. {
  176.     _pmgadgets_note Error error $*
  177. }
  178.  
  179. # standard warning
  180. # Usage: _pmgadgets_warning message goes in here
  181. #        _pmgadgets_warning -f file
  182. #
  183. _pmgadgets_warning()
  184. {
  185.     _pmgadgets_note Warning warning $*
  186. }
  187.  
  188. # standard info
  189. # Usage: _pmgadgets_info message goes in here
  190. #        _pmgadgets_info -f file
  191. #
  192. _pmgadgets_info()
  193. {
  194.     _pmgadgets_note Info info $*
  195. }
  196.  
  197. # generic notifier
  198. # Usage: _pmgadgets_note tag icon args ...
  199. #
  200. _pmgadgets_note()
  201. {
  202.     tag=$1; shift
  203.     icon=$1; shift
  204.     button=""
  205.     [ $tag = Error ] && button="-B Quit"
  206.  
  207.     if [ -z "$DISPLAY" -o "${PCP_USE_STDERR+yes}" = yes ]
  208.     then
  209.         if [ $# -eq 2 -a "X$1" = X-f ]
  210.         then
  211.             echo "$prog: $tag: ..."
  212.             cat $2
  213.         else
  214.             echo "$prog: $tag: $*"
  215.         fi
  216.     else
  217.         if [ $# -eq 2 -a "X$1" = X-f ]
  218.         then
  219.             /usr/bin/X11/xconfirm -icon $icon -file $2 -useslider -header "$tag $prog" $button >/dev/null 2>&1
  220.         else
  221.             /usr/bin/X11/xconfirm -icon $icon -t "$*" -noframe -header "$tag $prog" $button >/dev/null 2>&1
  222.         fi
  223.     fi
  224.  
  225.     [ $tag = Error ] && exit 1
  226. }
  227.  
  228.